<?php

class Member_move_model extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->table = 'member_move';
    }
    function getSearch($params, $sort = 'id', $order = 'asc') {
    	$this->db->select('member.*');
    	if ($params['full_name'] != '') {
    		$this->db->where("(member.first_name LIKE '%".$params['full_name']."%' OR last_name LIKE '%".$params['full_name']."%' OR email LIKE '%".$params['full_name']."%')");
    	}
    	if ($params['gender_value'] != '') {
    		$this->db->where('gender', $params['gender_value']);
    	}
    	if ($params['owner'] != '') {
    		$this->db->where('member.owner', 0);
    	}
    	if($params['owner_id'] == -1){
    		$this->db->where('member.owner', 0);
    	}else if ($params['owner_id'] != '') {
    		$this->db->where('member.owner', $params['owner_id']);
    	}
    	$this->db->join("member","member.id = member_move.member_id");
    	$this->db->order_by('member_move.' . $sort, $order);
    	$this->db->order_by('member_move.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    
    function getAll( $sort = 'id', $order = 'asc') {
    	$this->db->select('member.id, member.first_name, member.last_name, member_move.*');
    	$this->db->join("member","member.id = member_move.member_id");
    	$this->db->order_by('member_move.' . $sort, $order);
    	$this->db->order_by('member_move.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
    function getAllByMember($member_id, $sort = 'id', $order = 'asc') {
    	$this->db->select('member_move.* ');
    	$this->db->where('member_move.member_id = '.$owner_id );
    	$this->db->order_by('member_move.' . $sort, $order);
    	$this->db->order_by('member_move.update_date', 'desc');
    	$query = $this->db->get($this->table);
    	return $query->result();
    }
}

?>
